#extension GL_OES_EGL_image_external : require
precision mediump float;varying vec2 textureCoordinate;
uniform samplerExternalOES s_texture;
const float offset = 1.0f / 300.0f;
void main() {
    vec2 offsets[9];
    offsets[0] = vec2(-offset,  offset); // 左上
    offsets[1] = vec2( 0.0f,    offset); // 正上
    offsets[2] = vec2( offset,  offset); // 右上
    offsets[3] = vec2(-offset,  0.0f);   // 左
    offsets[4] = vec2( 0.0f,    0.0f);   // 中
    offsets[5] = vec2( offset,  0.0f);   // 右
    offsets[6] = vec2(-offset, -offset); // 左下
    offsets[7] = vec2( 0.0f,   -offset); // 正下
    offsets[8] = vec2( offset, -offset);  // 右下
    // 核函数
    float kernel[9];
    kernel[0] = 1.0f;
    kernel[1] = 1.0f;
    kernel[2] = 1.0f;
    kernel[3] = 1.0f;
    kernel[4] = -8.0f;
    kernel[5] = 1.0f;
    kernel[6] = 1.0f;
    kernel[7] = 1.0f;
    kernel[8] = 1.0f;
    // 计算采样值
    vec3 sampleTex[9];
    for(int i = 0; i < 9; i++)
    {
        sampleTex[i] = vec3(texture2D(s_texture, textureCoordinate.xy + offsets[i]));
    }
    vec3 col = vec3(0.0);
    for(int i = 0; i < 9; i++)
       col += sampleTex[i] * kernel[i];
    gl_FragColor = vec4(col, 1.0);
}